<template>
	<om-addpage style="padding-top: 35px;" :menuList='menuList' :showChooseBtn="ismenu" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		changeConfigAttr,
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey,
		getEditorTitle,		
		hasEditor
	} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import moment from '@/static/js/moment.js'
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				userIdCacheKey: 'qam-wgjy-productInspection-userId-cache',
				orderInstIdCacheKey: 'qam-wgjy-productInspection-orderInstId-cache',
				supplierIdCacheKey: 'qam-wgjy-productInspection-supplierId-cache',
				teamLeaderIdCacheKey: 'qam-wgjy-productInspection-teamLeaderId-cache',
				pieceUserCacheKey: 'qam-wgjy-productInspection-pieceUser-cache',
				reviewerIdCacheKey: 'qam-wgjy-productInspection-reviewerId-cache',
				ismenu:false,
				menuList:[],
				defaultDataCache:'qam-wgjy-productInspection-defaultData-cache'
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId','salaryInstId','salaryInstName'])
		},
		methods:{
			onSelectDisposalOfNonconformities(item){
				let _that = this
				if(_that.subEditorObj["title3"] && _that.subEditorObj["title3"].workList.length > 0){
					for(let obj of _that.subEditorObj["title3"].workList){
						obj.disposalOfNonconformitiesId = item.id
						obj.disposalOfNonconformities = item.text
					}
				}
			},
			verifyPieceUser(){
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				if(!formdata.productInstId){
					let title = _that.$refs.autoform.getEditorTitle("title1")
					let title1 = _that.$refs.autoform.getEditorTitle("productInstId")
					errorModal(_that,'提示信息',title+'中的'+title1+'需优先完成编辑',()=>{
						return false
					})
				}else{
					return true
				}
			},
			findInstByUserIdOrPostId(id){
				let _that = this
				_that.om.request(
					'orgInstPosUserOfficial/findInstByUserIdOrPostId',
					{
						userId: id,
						postId:''
					}
				,'post').then(res=>{
					_that.$refs.autoform.changeEditor("title1","instId","data",configSelectData(res,'id','instName'))
					if(!_that.$refs.autoform.formdata.instId){
						_that.$refs.autoform.initSelectVal("title1","instId")
					}else{
						_that.$refs.autoform.initSelectIndex("title1","instId")
					}
				})
			},
			onSubChange(editor){
				let _that = this.$refs.autoform
				let that = this
				if(editor.workList.length) {
					_that.formdata.unqualifiedId = ""
					_that.formdata.unqualified = ""
					_that.formdata.keyId = ""
					_that.formdata.keyName = ""
					_that.formdata.importantId = ""
					_that.formdata.importantName = ""
					for(let i=0; i<editor.workList.length; i++){
						if(i==0){
							_that.formdata.unqualifiedId = editor.workList[i].batchUnqualifiedId
							_that.formdata.unqualified = editor.workList[i].batchUnqualified
						}else{
							if(_that.formdata.unqualifiedId>editor.workList[i].batchUnqualifiedId){
								_that.formdata.unqualifiedId = editor.workList[i].batchUnqualifiedId
								_that.formdata.unqualified = editor.workList[i].batchUnqualified
							}
						}
						
						if(editor.workList[i].keyFlagId){
							if(editor.workList[i].keyFlagId == 6212){
								_that.formdata.importantId = editor.workList[i].keyFlagId
								_that.formdata.importantName = "√"
							}else{
								_that.formdata.keyId = editor.workList[i].keyFlagId
								_that.formdata.keyName = "√"
							}
						}
					}
				}
			},
			formSubmit(){
				let _that = this
				if(_that.subEditorObj["title3"]){
					let dataList = JSON.parse(_that.formdata.dataStr)
					for(let index in dataList){
						if(!dataList[index].fileList){
							delete dataList[index].fileList
						}
					}
					_that.formdata.dataStr = JSON.stringify(dataList)
				}
				if(_that.edit){
					_that.om.formSave("productInspection/doUpdate",_that.formdata,_that)
				}else{
					_that.om.formSave("productInspection/doAdd",_that.formdata,_that)
				}
			},
			initLoad(options){
				let _that = this
				let fileId = options.fileId
				let ajaxArr = [
					{
						url:'dictSource/loadCombo',
						param:{
							sourceId:'289',
							categoryId:'7510'
						}
					},{
						url:'dictSource/loadCombo',
						param:{
							sourceId:'283',
							categoryId:'6431'
						}
					},{
						url:'dictSource/loadCombo',
						param:{
							sourceId:'289',
							categoryId:'7549'
						}
					},{
						url:'dictSource/loadCombo',
						param:{
							sourceId:'289',
							categoryId:'8155'
						}
					},{
						url:'common/getMenu',
						param:{
							formCode:options.code
						}
					}]
					if(fileId){
						ajaxArr.push({
							url:"productInspection/getValue",
							param:{
								fileId:fileId
							}
						})
					}

				formModelLoad(ajaxArr,function(res,mainData){
					_that.menuList = res[4].value
					changeEditor("title2","reviewerPostId","data",configSelectData([],"id","posname"),mainData)
					changeEditor("title1","productInstId","data",configSelectData([],"id","instName"),mainData)
					changeEditor("title1","orderUserId","data",configSelectData([],"id","username"),mainData)
					changeEditor("title1","disposalOfNonconformitiesId","data",configSelectData(res[0],'id','text'),mainData)
					changeEditor("title1","keyId","data",configSelectData(res[1],'id','text'),mainData)
					changeEditor("title1","importantId","data",configSelectData(res[1],'id','text'),mainData)
					changeEditor("title1","unqualifiedId","data",configSelectData(res[2],'id','text'),mainData)
					changeEditor("title1","productionTeamId","data",configSelectData(res[3],'id','text'),mainData)
					changeEditor("title1","userId",{
						link:'../../public/searchUser/searchUser',
						"linkParam":{
							cachename: _that.userIdCacheKey,
							isSingle:true,
							isUserPos:true,
							isNew:true
						}
					},null,mainData)
					
					changeEditor("title1","teamLeaderId",{
						link:'../../public/searchUser/searchUser',
						"linkParam":{
							cachename: _that.teamLeaderIdCacheKey,
							isSingle:true,
							isUserPos:true,
							isNew:true
						}
					},null,mainData)
					
					changeEditor("title1","orderInstId",{
						"link":'../../public/search/search',
						"linkParam":{
							other:JSON.stringify(),
							url:'tinstitution/getComboTree',
							namefield:'text',
							initload:true,
							cachename:_that.orderInstIdCacheKey
						}
					},null,mainData)
					
					changeEditor("title1","supplierId",{
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							other:JSON.stringify({
								oldValue: ''
							}),
							url:'tsupplier/likeSerchAllSupplier',
							namefield:'supplierCode',
							notefield: "supplierName",
							initload:true,
							searchfield:'q',
							cachename:_that.supplierIdCacheKey
						}
					},null,mainData)
					
					changeEditor("title1","pieceUserIdStr",{
						link:'../../public/searchUser/searchUser',
						"linkParam":{
							cachename: _that.pieceUserCacheKey,
							defaultDataCache:_that.defaultDataCache,
							isUserPos:true,
							isNew:true
						}
					},null,mainData)
					
					changeEditor("title2","reviewerId",{
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							other:JSON.stringify({}),
							url:'temployee/getStaffCombogrid',
							namefield:'userPosInstName',
							initload:true,
							searchfield:'q',
							cachename:_that.reviewerIdCacheKey
						}
					},null,mainData)
					
					if (_that.subEditorObj['title3']) {
						let configData = _that.subConfigData['title3']
						let attr = {}
						if(hasEditor("title3",'newProductName',configData)){
							let title1 = getEditorTitle("title3","newProductName",configData)
							attr.titleTemplate = title1+':<%= newProductName || "无" %>'
						}
						if(hasEditor("title3",'batchInspectionConclusion',configData)){
							let title3 = getEditorTitle("title3","batchInspectionConclusion",configData)
							attr.subtitle2Template = title3+':<%= batchInspectionConclusion || "无" %>'
						}
						changeEditor("title3","dataStr",attr,mainData)
					}
					
					if(fileId){
						let fieldArr = getFormFields(mainData)
						fieldArr.push("id")
						for(let index in res[5].value){
							if(fieldArr.includes(index)){
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,index,res[5].value[index])
								_that.$set(_that.formdata,index,res[5].value[index])
							}
						}
						changeEditor("title1","userId",{
							link:'../../public/pageSearch/pageSearch',
							"linkParam":{
								other:JSON.stringify({
									firstUserId: res[5].value.userId
								}),
								url:'temployee/getStaffCombogrid',
								namefield:'userPosInstName',
								initload:true,
								searchfield:'q',
								cachename:_that.userIdCacheKey
							}
						},null,mainData)
						changeEditor("title2","reviewerId",{
							link:'../../public/pageSearch/pageSearch',
							"linkParam":{
								other:JSON.stringify({
									firstUserId: res[5].value.reviewerId
								}),
								url:'temployee/getStaffCombogrid',
								namefield:'userPosInstName',
								initload:true,
								searchfield:'q',
								cachename:_that.reviewerIdCacheKey
							}
						},null,mainData)
						changeEditor("title1","teamLeaderId",{
							link:'../../public/pageSearch/pageSearch',
							"linkParam":{
								other:JSON.stringify({
									firstUserId: res[5].value.teamLeaderId
								}),
								url:'temployee/getStaffCombogrid',
								namefield:'userPosInstName',
								initload:true,
								searchfield:'q',
								cachename:_that.teamLeaderIdCacheKey
							}
						},null,mainData)
						changeEditor("title1","supplierId",{
							link:'../../public/pageSearch/pageSearch',
							"linkParam":{
								other:JSON.stringify({
									oldValue: res[5].value.supplierId
								}),
								url:'tsupplier/likeSerchAllSupplier',
								namefield:'supplierCode',
								notefield: "supplierName",
								initload:true,
								searchfield:'q',
								cachename:_that.supplierIdCacheKey
							}
						},null,mainData)
						_that.om.request(
							'orgInstPosUserOfficial/findUserList',
							{
								instId: res[5].value.orderInstId
							},
						).then(res=>{
							_that.$refs.autoform.changeEditor("title1","orderUserId","data",configSelectData(res,"id","username"))
						})
						_that.om.request(
							'orgInstPosUserOfficial/findInstByUserIdOrPostId',
							{
								userId: res[5].value.productInstId
							},
						).then(res=>{
							_that.$refs.autoform.changeEditor("title1","productInstId","data",configSelectData(res,"id","instName"))
						})
						if(_that.$refs.autoform.formdata.pieceUserIdStr){
							let objArr = []
							let ids = _that.$refs.autoform.formdata.pieceUserIdStr.split(",")
							let names = _that.$refs.autoform.formdata.pieceUserNameStr.split(",")
							for(let index in ids){
								let obj = {
									id:ids[index],
									dicname:names[index]
								}
								objArr.push(obj)
								_that.$refs.autoform.changeEditor('title1', 'pieceUserIdStr', {
									initSelect: objArr
								})
							}
						}
						_that.om.request(
							'orgInstPosUserOfficial/getPosComboboxByUser',
							{
								userId: res[5].value.reviewerPostId,
								flag: true
							}
						).then(res=>{
							_that.$refs.autoform.changeEditor("title2","reviewerPostId","data",configSelectData(res,"id","posname"))
							_that.$refs.autoform.initSelectIndex("title2","reviewerPostId")
						})
						if(_that.subEditorObj["title3"]){
							let datalist = res[5].value.dataList
							_that.subEditorObj["title3"].workList = datalist
							_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"dataStr",JSON.stringify(datalist))
							_that.$set(_that.formdata,"dataStr",JSON.stringify(datalist))
						}
						_that.$nextTick(function(){
							_that.$refs.autoform.initSelectIndex("title1","disposalOfNonconformitiesId")
							_that.$refs.autoform.initSelectIndex("title1","keyId")
							_that.$refs.autoform.initSelectIndex("title1","importantId")
							_that.$refs.autoform.initSelectIndex("title1","unqualifiedId")
							_that.$refs.autoform.initSelectIndex("title1","productionTeamId")
						})
					}
					
					_that.$nextTick(function(){
						if(!_that.$refs.autoform.formdata.userId){
							_that.$refs.autoform.formdata.userId = _that.userId
							_that.$refs.autoform.formdata.userName = _that.userName
						}
						if(!_that.$refs.autoform.formdata.instId){
							_that.$refs.autoform.formdata.instId = _that.salaryInstId
							_that.$refs.autoform.formdata.instName = _that.salaryInstName
							_that.findInstByUserIdOrPostId(_that.$refs.autoform.formdata.userId)
						}
						if(!_that.$refs.autoform.formdata.incomingDate){
							_that.$refs.autoform.formdata.incomingDate = moment().format('YYYY-MM-DD')
						}
					})
				},options)
			},
			clearUserId(){
				let _that = this
				_that.$refs.autoform.clear("title1",'userId')
				_that.$refs.autoform.clear("title1",'instId')
			},
			clearOrderInstId(){
				let _that = this
				_that.$refs.autoform.clear("title1",'orderInstId')
				_that.$refs.autoform.clear("title1",'orderUserId')
				_that.$refs.autoform.changeEditor("title1","orderUserId","data",configSelectData([],"id","username"))
			},
			clearSupplierCoding(){
				let _that = this
				_that.$refs.autoform.clear("title1",'supplierId')
				_that.$refs.autoform.clear("title1",'supplierCode')
				_that.$refs.autoform.clear("title1",'supplierName')
				_that.$refs.autoform.clear("title1",'supplierShortName')
			},
			onselectProductDate(data){
				let _that = this
				if (new Date(data).getTime() > new Date(_that.$refs.autoform.formdata.incomingDate).getTime()) {
					errorModal(_that,'提示信息',"生产日期不能晚于检验日期",()=>{
						_that.$refs.autoform.clear("title1",'productDate')
					})
				}else{
					let formdata = _that.$refs.autoform.formdata
					if(_that.subEditorObj['title3'] && _that.subEditorObj['title3'].workList.length>0){
						let dataList = _that.subEditorObj['title3'].workList
						for(let index in dataList){
							dataList[index].productDate = data
						}
						formdata.dataStr = JSON.stringify(dataList)
						if(_that.subEditorObj['title3']){
							_that.subEditorObj['title3'].workList = dataList
						}
						_that.om.toast('子表数据已更新')
					}
				}
			},
			getWorkParam() {
				let _that = this
				let formdata = _that.$refs.autoform.formdata
				return {
					incomingDate:formdata.incomingDate,
					productTeamId:formdata.productionTeamId,
					productInstId:formdata.productInstId,
				};
			},
			clearReviewerId(){
				let _that = this
				_that.$refs.autoform.clear("title2",'reviewerId')
				_that.$refs.autoform.clear("title2",'reviewerPostId')
				_that.$refs.autoform.clear("title2",'reviewerInstId')
			},
			clearReviewerPostId(){
				let _that = this
				_that.$refs.autoform.clear("title2",'reviewerPostId')
				_that.$refs.autoform.clear("title2",'reviewerInstId')
			},
			onselectReviewerPostId(item){
				let _that = this
				_that.$refs.autoform.formdata.reviewerPostId = item.id
				_that.$refs.autoform.formdata.reviewerPostName = item.posname
				_that.$refs.autoform.formdata.reviewerInstId = item.instId
				_that.$refs.autoform.formdata.reviewerInstName = item.instName
			},
			clearTeamLeaderName(){
				let _that = this
				_that.$refs.autoform.clear("title1",'teamLeaderId')
				_that.$refs.autoform.clear("title1",'productInstId')
				_that.$refs.autoform.changeEditor("title1","productInstId","data",configSelectData([],"id","instName"))
				_that.getUnqualifiedBatchNumber(_that.$refs.autoform.formdata.productionTeamId,"")
			},
			onselectProductInstName(item){
				let _that = this
				_that.$refs.autoform.formdata.productInstId = item.id
				_that.$refs.autoform.formdata.productInstName = item.instname
				_that.getUnqualifiedBatchNumber(_that.$refs.autoform.formdata.productionTeamId,item.id)
			},
			clearProductInstName(){
				let _that = this
				_that.$refs.autoform.clear("title1",'productInstId')
				_that.getUnqualifiedBatchNumber(_that.$refs.autoform.formdata.productionTeamId,"")
			},
			onselectProductionTeamName(item){
				let _that = this
				_that.$refs.autoform.formdata.productionTeamId = item.id
				_that.$refs.autoform.formdata.productionTeamName = item.text
				_that.getUnqualifiedBatchNumber(item.id,_that.$refs.autoform.formdata.productInstId)
			},
			clearProductionTeamName(){
				let _that = this
				_that.$refs.autoform.clear("title1",'productionTeamId')
				_that.getUnqualifiedBatchNumber("",_that.$refs.autoform.formdata.productInstId)
			},
			getUnqualifiedBatchNumber(productionTeamId,productInstId){
				let _that = this
				_that.om.request(
					'productInspection/getInstQuality',
					{
						productionTeamId: productionTeamId,
						productInstId: productInstId,
					},
				'post').then(res=>{
					_that.$refs.autoform.formdata.unqualifiedBatchNumber = res.value
				})
			}
		},
		onUnload() {
			let _that = this
				uni.removeStorage({
					key:_that.defaultDataCache
				})
			//#ifdef APP-PLUS
				if (_that.$refs.autoform) {
					for (var fieldId in _that.subEditorObj) {
						uni.removeStorage({
							key: getWorkCacheKey(fieldId)
						});
					}
				}
			//#endif
		},
		onLoad(options) {
			let _that = this
			_that.initLoad(options)
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				for (var fieldId in _that.subEditorObj) {
					var editor = _that.subEditorObj[fieldId];
					uni.getStorage({
						key: getWorkCacheKey(fieldId),
						success: function(res) {
							editor.workList = res.data;
							let formdata = _that.$refs.autoform.formdata
							for(let item of res.data){
								if(item.disposalOfNonconformitiesId && item.disposalOfNonconformitiesId != formdata.disposalOfNonconformitiesId){
									_that.$refs.autoform.clear("title1","disposalOfNonconformitiesId")
								}
							}
							_that.onSubChange(editor)
							uni.removeStorage({
								key: getWorkCacheKey(fieldId)
							});
						}
					});
				};
				uni.getStorage({
					key:_that.userIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.userId = d.id
							formdata.userName = d.username
							_that.$refs.autoform.clear("title1","instId")
							_that.findInstByUserIdOrPostId(d.id)
							uni.removeStorage({
								key:_that.userIdCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.reviewerIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							let isbhg = false;
							for(let i=0; i<_that.subEditorObj['title3'].workList.length; i++){
								if(_that.subEditorObj['title3'].workList[i].batchInspectionConclusionId == 6226){
									isbhg = true
								}
							}
							
							if(isbhg){
								errorModal(_that,'提示信息',"批检验结论没有不合格的物料，不能选择让步接收评审人！",()=>{
									_that.clearReviewerId()
								})
							}else if(d.id == formdata.userId){
								errorModal(_that,'提示信息',"让步接收评审人不能为检验员！",()=>{
									_that.clearReviewerId()
								})
							}else{
								formdata.reviewerId = d.id
								formdata.reviewerName = d.username
								_that.$refs.autoform.changeEditor('title2', 'reviewerId', {
									linkParam: {
										other:JSON.stringify({
											firstUserId: d.id
										}),
										url:'temployee/getStaffCombogrid',
										namefield:'userPosInstName',
										initload:true,
										searchfield:'q',
										cachename:_that.reviewerIdCacheKey
									}
								});
								_that.om.request(
									'orgInstPosUserOfficial/getPosComboboxByUser',
									{
										userId: d.id,
										flag: true
									}
								).then(res=>{
									formdata.reviewerPostId = d.salaryPosId
									formdata.reviewerPostName = d.salaryPosName
									formdata.reviewerInstId = d.salaryPosInstId
									formdata.reviewerInstName = d.salaryPosInstName
									_that.$refs.autoform.changeEditor("title2","reviewerPostId","data",configSelectData(res,"id","posname"))
									_that.$refs.autoform.initSelectIndex("title2","reviewerPostId")
								})
							}
							
							uni.removeStorage({
								key:_that.reviewerIdCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key: _that.orderInstIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							if(formdata.orderInstId != d.id){
								_that.om.request(
									'orgInstPosUserOfficial/findUserList',
									{
										instId: d.id
									},
								).then(res=>{
									_that.$refs.autoform.changeEditor("title1","orderUserId","data",configSelectData(res,"id","username"))
									_that.$refs.autoform.clear("title1",'orderUserId')
								})
							}
							formdata.orderInstId = d.id
							formdata.orderInstName = d.text	
							uni.removeStorage({
								key: _that.orderInstIdCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key:_that.supplierIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.supplierId = d.id
							formdata.supplierCoding = d.supplierCode2
							formdata.supplierCode = d.supplierCode
							formdata.supplierName = d.supplierName
							formdata.supplierShortName = d.supplierShortName 
							_that.$refs.autoform.changeEditor('title1', 'supplierId', {
								linkParam: {
									other:JSON.stringify({
										oldValue: d.id
									}),
									url:'tsupplier/likeSerchAllSupplier',
									namefield:'supplierCode',
									notefield: "supplierName",
									initload:true,
									searchfield:'q',
									cachename:_that.supplierIdCacheKey
								}
							});
							uni.removeStorage({
								key:_that.supplierIdCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.teamLeaderIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.teamLeaderId = d.id
							formdata.teamLeaderName = d.username
							_that.om.request(
								'orgInstPosUserOfficial/findInstByUserIdOrPostId',
								{
									userId: d.id
								}
							).then(res=>{
								_that.$refs.autoform.changeEditor("title1","productInstId","data",configSelectData(res,"id","instName"))
								formdata.productInstId = d.salaryPosInstId
								formdata.productInstName = d.salaryPosInstName
								_that.getUnqualifiedBatchNumber(_that.$refs.autoform.formdata.productionTeamId,d.salaryPosInstId)
								_that.$nextTick(function(){
									_that.$refs.autoform.initSelectIndex("title1","productInstId")
								})
							})
							uni.removeStorage({
								key:_that.teamLeaderIdCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.pieceUserCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data;
							uni.setStorage({
								key:_that.defaultDataCache,
								data:d
							})
							let formdata = _that.$refs.autoform.formdata;
							let idList = []
							let nameList = []
							let pieceUserIdStr = ''
							if(formdata.pieceUserIdStr){
								pieceUserIdStr = formdata.pieceUserIdStr.split(',')
							}
							for(let index in d){
								idList.push(d[index].id)
								nameList.push(d[index].username)
							}
							let idStr = idList.map(e =>e).join(",")
							let nameStr = nameList.map(e =>e).join(",");
							formdata.pieceUserIdStr = idStr
							formdata.pieceUserNameStr = nameStr
							uni.removeStorage({
								key: _that.pieceUserCacheKey
							});
						}
					}
				})
				try {
					const value = uni.getStorageSync('chooseData');
					if (value) {
						let arr = []
						let obj = {}
						let fieldArr = []
						if(_that.subEditorObj["title3"]){
							let conifgData = _that.subConfigData["title3"]
							fieldArr = getFormFields(conifgData)
							for(let index in fieldArr){
								_that.$set(obj,fieldArr[index],'')
							}
						}
						for(let item of value){
							let data = Object.assign({},obj)
							for(let subItem of item.subData){
								if(subItem.checked){
									for(let dataIndex in fieldArr){
										_that.$set(data,dataIndex,subItem[dataIndex]?subItem[dataIndex]:'')
									}
									arr.push(subItem)
								}
							}
						}
						_that.om.request(
							'purchaseArrive/getListByIds',
							{
								dataStr:JSON.stringify(arr)
							},
							'post'
						).then(res=>{
							for(let index in res){
								delete arr[index].id
								arr[index].quantity = res[index].quantity
								if(_that.subEditorObj["title3"]){
									_that.subEditorObj["title3"].workList = arr
								}
							}
						})
						uni.removeStorageSync('chooseData')
					}
				}catch(e){
					
				}
			}
		}
	}
</script>
<style></style>                                                                                                                                                                                                                                                                                                                  
